package com.example.activitydatatransfer;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    Button btnChange1,btnCancel1;
    EditText editTextName1,editTextScore1,editTextPassed1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btnChange1=(Button) findViewById(R.id.btnChange1);
        btnCancel1=(Button) findViewById(R.id.btnCancel1);
        btnChange1.setOnClickListener(this);
        btnCancel1.setOnClickListener(this);
        editTextName1=(EditText) findViewById(R.id.editTextName1);
        editTextScore1=(EditText) findViewById(R.id.editTextScore1);
        editTextPassed1=(EditText) findViewById(R.id.editTextPassed1);
    }

    @Override
    public void onClick(View view) {
        switch(view.getId()){
            case R.id.btnChange1:
                Intent intent=new Intent(this,SecondActivity.class);
                intent.putExtra("studentName",editTextName1.getText().toString());
                intent.putExtra("englishScore",editTextScore1.getText().toString());
                intent.putExtra("isPassed",editTextPassed1.getText().toString());
                int requestCode=1;
                startActivityForResult(intent,requestCode);
                break;
            case R.id.btnCancel1:
                this.finish();
//                Intent intent1=new Intent(Intent.ACTION_DIAL);
//                intent1.setData(Uri.parse("tel:12345678"));
//                startActivity(intent1);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        //super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==1&&resultCode==2){
            editTextName1.setText(data.getStringExtra("studentName"));
            editTextScore1.setText(data.getStringExtra("englishScore"));
            editTextPassed1.setText(data.getStringExtra("isPassed"));
        }
    }
}
